/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/phone/ThreadMonitor.h,v 1.3 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */

#ifndef __THREADMONITOR_H__

// uncomment this if you want to monitor thread usage of the machine, and the ui.
// #define _USE_THREADMONITOR 1

#include "nhThread.h"
#include <windows.h>
#include <map>
#include <string>

struct ThreadTimeInfo {
    DWORD kernel;
    DWORD user;
    DWORD current;
};
typedef std::map<DWORD,ThreadTimeInfo> ThreadTimeInfoMap;

class ThreadMonitor : public NHThread {
public:
    ThreadMonitor();
    ~ThreadMonitor();

protected:
    virtual DWORD ThreadProc();
    virtual const char* name() const { return "ThreadMonitor"; }

private:
        DWORD m_spcore_pid;
        ThreadTimeInfoMap m_spcore_times;

        DWORD m_ui_pid;
        ThreadTimeInfoMap m_ui_times;

    void WriteThreadUsage(const ThreadTimeInfoMap& prev, const ThreadTimeInfoMap& cur);
    DWORD GetProcessId(const std::string& processname);
    void GetProcessThreadTimes(DWORD pid, ThreadTimeInfoMap& times);
};

#define __THREADMONITOR_H__
#endif
